<template>
  <el-dialog
      :model-value="dialogVisible"
      :title="props.dialogCpTitle"
      width="40%"
      @close="handleClose"
  >
    <el-form size="default" :model="form" ref="formRef" label-width="130px" :rules="rules"  >
      <el-form-item label="产地名称" prop="chandi">
        <el-select v-model="form.chandi" clearable placeholder="请选择" size="large">
          <el-option
              v-for="(item, index) in chandiName"
              :key="index"
              :label="item"
              :value="item"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="产品名称" prop="cpmc">
        <el-select v-model="form.cpmc" clearable placeholder="请选择" size="large">
          <el-option
              v-for="(item, index) in chanpingName"
              :key="index"
              :label="item"
              :value="item"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="生产负责人" prop="scfzr" size="large">
        <el-input v-model="form.scfzr" clearable/>
      </el-form-item>
      <el-form-item label="生产日期" prop="scrq" >
        <el-date-picker
            v-model="form.scrq"
            type="date"
            placeholder="选择日期"
            :size="'large'"
            clearable
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleConfirm">
          确认
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import {defineEmits, ref, defineProps, onMounted} from 'vue'
import {getOptionInfo, getOptionsInfo} from "@/api/methods/initInfo.js";
import {getAllCdmc, getAllCpmc, getAllIotCdmc} from "@/api/apiPath/twoPart.js";

const props = defineProps({
  dialogCpTitle: {
    type: String,
    default: '',
    required: true
  },
  dialogCpTableValue: {
    type: Object,
    default: {}
  },
  queryForm: {
  },
  dialogVisible: {
    type: Boolean,
    default: false
  }
})
const formRef = ref(null)
const form = ref({
  chandi: '',
  cpmc: '',
  scfzr: '',
  scrq: '',
})
const chandiName = ref([])
const chanpingName = ref([])

onMounted( async ()=> {
  chandiName.value =  await getOptionInfo(getAllIotCdmc())
  getOptionsInfo(getAllCpmc(), chanpingName)
  form.value = props.dialogCpTableValue
})

const rules = ref({
  chandi: [{
    required: true,
    message: '不能为空',
    trigger: ['blur', 'change'],
  }],
  cpmc: [{
    required: true,
    message: '不能为空',
    trigger: ['blur', 'change'],
  }],
  scfzr: [{
    required: true,
    message: '不能为空',
    trigger: ['blur', 'change'],
  }],
  scrq: [{
    required: true,
    message: '不能为空',
    trigger: ['blur', 'change'],
  }],
})
const emits = defineEmits(['update:modelValue', 'handleConfirm'])
const handleClose = ()=> {
  emits('update:modelValue', false)
}
const handleConfirm = () => {
  emits("handleConfirm", {...form.value}, {...formRef.value})
}
</script>

<style scoped>


</style>